(function(){

YAHOO.pendular.RepositoryResultDataSource = function(config){
    if (!config) {
        config = {};
    }
    YAHOO.lang.augmentObject(config, {
        repository: YAHOO.pendular.app.repository
    });
    this.config = config;
    YAHOO.pendular.RepositoryResultDataSource.superclass.constructor.call(    
        this, 
        this.searchRepository,
        config
    );
    this.responseSchema = {
        fields: [
            "key",
            "name", 
            "lastModifiedDate",
            "localizedName", 
            "description",
            "isDirectory",
            "visible",
            "isDirectory",
            "url",
            "extension"
        ]
    };
};

YAHOO.extend(YAHOO.pendular.RepositoryResultDataSource, YAHOO.util.FunctionDataSource, {
    searchRepository: function(query) {        
        var config = this.config,
            repository = config.repository,
            repositoryKeywords = repository.keywords,
            keywords = repositoryKeywords.makeKeywords(
                decodeURIComponent(query)
            ),
            numKeywords = keywords.length,
            entries, entry, key, result = [];
        ;
        if (!numKeywords) {
            return [];
        }
        entries = repositoryKeywords.getKeywordEntries(keywords);
        for (key in entries){
            result.push(entries[key]);
        }
        return result;
    }    
});

})();
